 <!--
* description: 城市仓库信息维护
* author: duanhy
* createdDate: 2020-12-5
-->
<template>
  <section class="app-container app-container-table">
    <div id="TreeTable">
      <!--树形区域-->
      <el-aside class="el-slide">
        <el-input
          v-model="filterText"
          placeholder="输入关键字进行过滤"
        />
        <el-tree
          ref="tree"
          :expand-on-click-node="false"
          default-expand-all
          :data="menueList"
          highlight-current
          :props="defaultProps"
          :filter-node-method="filterNode"
          @node-click="handleNodeClick"
        />
      </el-aside>
      <el-main ref="mainHeight">
        <div class="hander-bg">
          <div class="filter-container filter-params" style="height:calc(100vh - 109px)">
            <div v-if="color" class="filter-container filter-title">{{ formtitle }}</div>
            <el-button v-show="btnshow" @click="add(btn)">{{ btn }}</el-button>
            <one-table-template
              ref="multipleTable"
              :key="setid"
              v-loading="formloading"
              :dynamic-api-config="apiConfig"
              :dynamic-buttons="dynamicButton"
              :dynamic-components="tableComponent"
              :dynamic-form-fields="formField"
              :dynamic-is-show-more-btn="true"
            />
          </div>
        </div>
      </el-main>
    </div>
  </section>
</template>
<script>
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import Vue from 'vue'
import api from '@/api/apiVeData'
export default {
  name: 'CityInfo',
  components: {
    OneTableTemplate
  },
  filters: {},
  mixins: [oneTableWithViewTemplateMixins],
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData(
      // 同时加载当前页面和编辑框页面的配置
      to.path,
      function() {
        next()
      })
  },
  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path
    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])
    return {
      // 重置状态
      resetstatus: '',
      // 树形结构
      formloading: false,
      provinceList: [],
      cityList: [],
      countyList: [],
      carAreaName: '',
      getCityId: '',
      color: false,
      provinceId: '',
      carStockAreaId: '',
      carAreaCode: '',
      carPlaceName: '',
      houseId: '',
      name: '',
      type: 0,
      list: [],
      provinceArr: [],
      cityArr: [],
      countyArr: [],
      menueParam: {},
      menueList: [],
      menueListBF: [],
      nodeBF: [],
      defaultProps: {
        children: 'children',
        label: 'label'
      },

      // 网格查询API配置对象
      apiConfig: {},
      formtitle: '',
      dynamicButton: [],
      dynamicButtons:
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode] &&
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode].tableButtons &&
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode].tableButtons
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[viewPageCode].tableButtons
          : [
            {
              compKey: 'btnKey1',
              type: 'primary',
              size: 'small',
              name: 'save',
              clickEvent: () => this.save(),
              text: '保存'
            },
            {
              compKey: 'btnKey2',
              type: '',
              size: 'small',
              icon: 'iconfont  icon-cancel',
              clickEvent: () => this.newreset(),
              text: '重置',
              name: 'reset'
            }
          ],
      // 动态组件-查询条件\
      tableComponent: [],
      // 新增仓库 --点击门店
      tableComponents: [
        {
          compKey: 'compKey1',
          labelName: '仓库编码：',
          codeField: 'carHouseCode',
          isRequire: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8,
          validrule: {
            min: 1,
            maxlength: 4
          }
        },
        {
          compKey: 'compKey2',
          labelName: '仓库名称：',
          codeField: 'carHouseName',
          isRequire: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8,
          validrule: {
            min: 1
            // maxlength: 10
          }
        },
        {
          compKey: 'compKey3',
          labelName: '管理员姓名：',
          codeField: 'carHouseManager',
          isRequire: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8,
          validrule: {
            // isformat: /^[\u4e00-\u9fa5]{2,6}$/
            maxlength: 25
          }
        },
        {
          compKey: 'compKey4',
          labelName: '管理员电话：',
          codeField: 'carHouseTel',
          isRequire: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8,
          validrule: {
            isformat: /(\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$/
          }
        },
        {
          compKey: 'compKey5',
          labelName: '传真：',
          codeField: 'carHouseFax',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8,
          validrule: {
            isformat: /^(?:\d{3,4}-)?\d{7,8}(?:-\d{1,6})?$/
          }
        },
        {
          compKey: 'compKey6',
          labelName: '邮编：',
          codeField: 'zip',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8,
          validrule: {
            isformat: /^[1-9]\\d{5}$/
          }
        },
        {
          compKey: 'compKey7',
          labelName: '省份：',
          codeField: 'provinceId',
          isRequire: true,
          component: () => import('@/components/org/LookupValue'), // ProvinceQuery
          type: 'dropdownList',
          isMust: true,
          isMul: false,
          span: 8,
          oFields: 'provinceId,provinceName',
          options: [
            { provinceId: '', provinceName: '' }
          ]
        },
        {
          compKey: 'compKey8',
          labelName: '城市：',
          codeField: 'cityId',
          isRequire: true,
          component: () => import('@/components/org/LookupValue'), // CitySelect
          type: 'dropdownList',
          isMust: true,
          span: 8,
          oFields: 'cityId,cityName',
          options: [
            { cityId: '', cityName: '' }
          ]
        },
        {
          compKey: 'compKey9',
          labelName: '区县：',
          codeField: 'countyId',
          textField: 'countyName',
          isRequire: true,
          component: () => import('@/components/org/LookupValue'), //  CountySelect
          type: 'dropdownList',
          isMust: true,
          span: 8,
          oFields: 'countyId,countyName',
          options: [
            { countyName: '', countyId: '' }
          ]
        },
        {
          compKey: 'compKey10',
          labelName: '详细地址：',
          codeField: 'carHouseAddr',
          isRequire: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8
        },
        {
          compKey: 'compKey11',
          labelName: '默认搬入地：',
          codeField: 'isDefaultAddr',
          isRequire: true,
          component: () => import('@/components/org/LookupValue'),
          type: 'dropdownList',
          isMust: true,
          span: 8,
          oFields: 'isDefaultAddr,isDefaultName',
          options: [
            { isDefaultAddr: '1', isDefaultName: '是' },
            { isDefaultAddr: '0', isDefaultName: '否' }
          ]
        },
        // {
        //   compKey: 'compKey12',
        //   labelName: 'SAP销售公司编码：',
        //   codeField: 'salesCompanyCode',
        //   isRequire: true,
        //   component: () => import('@/components/org/commonInput'),
        //   type: 'inputText',
        //   isMust: true,
        //   span: 8,
        //   validrule: {
        //     min: 1,
        //     maxlength: 10
        //   }
        // },
        // {
        //   compKey: 'compKey13',
        //   labelName: 'SAP仓库编码：',
        //   codeField: 'sapCode',
        //   isRequire: true,
        //   component: () => import('@/components/org/commonInput'),
        //   type: 'inputText',
        //   isMust: true,
        //   span: 8,
        //   validrule: {
        //     min: 1,
        //     maxlength: 10
        //   }
        // },
        // {
        //   compKey: 'compKey14',
        //   labelName: 'SAP销售公司名称：',
        //   codeField: 'salesCompanyName',
        //   isRequire: true,
        //   component: () => import('@/components/org/commonInput'),
        //   type: 'inputText',
        //   isMust: true,
        //   span: 8,
        //   validrule: {
        //     min: 1,
        //     maxlength: 10
        //   }
        // },
        {
          compKey: 'compKey15',
          labelName: '启用状态：',
          codeField: 'isEnable',
          isRequire: true,
          component: () => import('@/components/org/isEnable/isEnableOne'),
          type: 'dropdownList',
          isMust: true,
          span: 8
        },
        {
          compKey: 'compKey16',
          labelName: '备注：',
          codeField: 'remark',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8
        }
      ],
      // 修改仓库 --点击仓库
      tableComponents1: [
        {
          compKey: 'compKey1',
          labelName: '仓库编码：',
          codeField: 'carHouseCode',
          isRequire: true,
          disabled: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8,
          validrule: { // 验证
            min: 1,
            maxlength: 4
          }
        },
        {
          compKey: 'compKey2',
          labelName: '仓库名称：',
          codeField: 'carHouseName',
          isRequire: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8,
          validrule: {
            min: 1
          }
        },
        {
          compKey: 'compKey3',
          labelName: '管理员姓名：',
          codeField: 'carHouseManager',
          isRequire: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8,
          validrule: {
            // isformat: /^[\u4e00-\u9fa5]{2,6}$/
            maxlength: 25
          }
        },
        {
          compKey: 'compKey4',
          labelName: '管理员电话：',
          codeField: 'carHouseTel',
          isRequire: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8,
          validrule: {
            isformat: /(\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$/
          }
        },
        {
          compKey: 'compKey5',
          labelName: '传真：',
          codeField: 'carHouseFax',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8,
          validrule: {
            isformat: /^(?:\d{3,4}-)?\d{7,8}(?:-\d{1,6})?$/
          }
        },
        {
          compKey: 'compKey6',
          labelName: '邮编：',
          codeField: 'zip',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8,
          validrule: {
            isformat: /^[1-9]\\d{5}$/
          }
        },
        {
          compKey: 'compKey7',
          labelName: '省份：',
          codeField: 'provinceId',
          isRequire: true,
          component: () => import('@/components/org/LookupValue'),
          type: 'dropdownList',
          isMust: true,
          isMul: false,
          span: 8,
          oFields: 'provinceId,provinceName',
          options: [
            { provinceId: '', provinceName: '' }
          ]
        },
        {
          compKey: 'compKey8',

          labelName: '城市：',
          codeField: 'cityId',
          isRequire: true,
          component: () => import('@/components/org/LookupValue'), // CitySelect
          type: 'dropdownList',
          isMust: true,
          span: 8,
          oFields: 'cityId,cityName',
          options: [
            { cityId: '', cityName: '' }
          ]
        },
        {
          compKey: 'compKey9',
          labelName: '区县：',
          codeField: 'countyId',
          textField: 'countyName',
          isRequire: true,
          component: () => import('@/components/org/LookupValue'),
          type: 'dropdownList',
          isMust: true,
          span: 8,
          oFields: 'countyId,countyName',
          options: [
            { countyName: '', countyId: '' }
          ]
        },
        {
          compKey: 'compKey10',
          labelName: '详细地址：',
          codeField: 'carHouseAddr',
          isRequire: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8
        },
        {
          compKey: 'compKey11',
          labelName: '默认搬入地：',
          codeField: 'isDefaultAddr',
          component: () => import('@/components/org/LookupValue'),
          type: 'dropdownList',
          isMust: true,
          span: 8,
          oFields: 'isDefaultAddr,isDefaultName',
          options: [
            { isDefaultAddr: '1', isDefaultName: '是' },
            { isDefaultAddr: '0', isDefaultName: '否' }
          ]
        },
        // {
        //   compKey: 'compKey12',
        //   labelName: 'SAP销售公司编码：',
        //   codeField: 'salesCompanyCode',
        //   isRequire: true,
        //   component: () => import('@/components/org/commonInput'),
        //   type: 'inputText',
        //   isMust: true,
        //   span: 8,
        //   validrule: {
        //     min: 1,
        //     maxlength: 10
        //   }
        // },
        // {
        //   compKey: 'compKey13',
        //   labelName: 'SAP仓库编码：',
        //   codeField: 'sapCode',
        //   isRequire: true,
        //   component: () => import('@/components/org/commonInput'),
        //   type: 'inputText',
        //   isMust: true,
        //   span: 8,
        //   validrule: {
        //     min: 1,
        //     maxlength: 10
        //   }
        // },
        // {
        //   compKey: 'compKey14',
        //   labelName: 'SAP销售公司名称：',
        //   codeField: 'salesCompanyName',
        //   isRequire: true,
        //   component: () => import('@/components/org/commonInput'),
        //   type: 'inputText',
        //   isMust: true,
        //   span: 8,
        //   validrule: {
        //     min: 1,
        //     maxlength: 10
        //   }
        // },
        {
          compKey: 'compKey15',
          labelName: '启用状态：',
          codeField: 'isEnable',
          isRequire: true,
          component: () => import('@/components/org/isEnable/isEnableOne'),
          type: 'dropdownList',
          isMust: true,
          span: 8
        },
        {
          compKey: 'compKey16',
          labelName: '备注：',
          codeField: 'remark',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8
        }
      ],
      // 修改储区
      tableComponents2: [
        {
          compKey: 'compKey17',
          labelName: '仓库名称：',
          codeField: 'carHouseName', // 整车仓库id carStockHouseId
          isRequire: true,
          disabled: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8
        },
        {
          compKey: 'compKey18',
          labelName: '储区编码：',
          codeField: 'carAreaCode',
          isRequire: true,
          disabled: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8
        },
        {
          compKey: 'compKey19',
          labelName: '管理员：',
          codeField: 'carAreaManager',
          isRequire: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8
          // validrule: {
          //   isformat: /^[\u4e00-\u9fa5]{2,6}$/
          // }
        },
        {
          compKey: 'compKey20',
          labelName: '启用状态：',
          codeField: 'isEnable',
          isRequire: true,
          component: () => import('@/components/org/isEnable/isEnableOne'),
          type: 'dropdownList',
          isMust: true,
          span: 8
        },
        {
          compKey: 'compKey21',
          labelName: '备注：',
          codeField: 'remark',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8
        } // 角色名称
      ],
      // 修改库位
      tableComponents3: [
        {
          compKey: 'compKey22',
          labelName: '仓库名称：',
          codeField: 'carHouseName',
          isRequire: true,
          disabled: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8
        },
        {
          compKey: 'compKey23',
          labelName: '储区编码：',
          codeField: 'carAreaCode',
          isRequire: true,
          disabled: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8
        },
        {
          compKey: 'compKey24',
          labelName: '库位编码：',
          codeField: 'carPlaceCode',
          isRequire: true,
          disabled: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8
        },
        {
          compKey: 'compKey25',
          labelName: '启用状态：',
          codeField: 'isEnable',
          isRequire: true,
          component: () => import('@/components/org/isEnable/isEnableOne'),
          type: 'dropdownList',
          isMust: true,
          span: 8
        },
        {
          compKey: 'compKey26',
          labelName: '备注：',
          codeField: 'remark',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8
        } // 角色名称
      ],
      // 新增---库位   --点击储区
      tableComponents4: [
        {
          compKey: 'compKey27', // 整车仓库id  carStockHouseId
          labelName: '仓库名称：',
          codeField: 'carHouseName',
          isRequire: true,
          disabled: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8
        },
        {
          compKey: 'compKey28',
          labelName: '储区编码：',
          codeField: 'carAreaCode',
          isRequire: true,
          disabled: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8
        },
        {
          compKey: 'compKey29',
          labelName: '库位编码：',
          codeField: 'carPlaceCode',
          isRequire: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8
        },
        {
          compKey: 'compKey30',
          labelName: '启用状态：',
          codeField: 'isEnable',
          isRequire: true,
          component: () => import('@/components/org/isEnable/isEnableOne'),
          type: 'dropdownList',
          isMust: true,
          span: 8
        },
        {
          compKey: 'compKey31',
          labelName: '备注：',
          codeField: 'remark',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8
        } // 角色名称
      ],
      // 新增---储区
      tableComponents5: [
        {
          compKey: 'compKey32', // 储区ID carStockHouseId
          labelName: '仓库名称：',
          codeField: 'carHouseName',
          isRequire: true,
          disabled: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8
        },
        {
          compKey: 'compKey33',
          labelName: '储区编码：',
          codeField: 'carAreaCode',
          isRequire: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8,
          validrule: {
            min: 1,
            maxlength: 10
          }
        },
        {
          compKey: 'compKey34',
          labelName: '管理员',
          codeField: 'carAreaManager',
          isRequire: true,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8,
          validrule: {
            isformat: /^[\u4e00-\u9fa5]{2,6}$/
          }
        },
        {
          compKey: 'compKey35',
          labelName: '启用状态：',
          codeField: 'isEnable',
          isRequire: true,
          component: () => import('@/components/org/isEnable/isEnableOne'),
          type: 'dropdownList',
          isMust: true,
          span: 8
        },
        {
          compKey: 'compKey36',
          labelName: '备注：',
          codeField: 'remark',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          span: 8
        }
      ],
      // 表单查询数据
      // 仓库信息维护
      formField: {
        provinceId: '',
        cityId: '',
        countyId: ''
      },
      formFieldBF: {
        provinceId: '',
        cityId: '',
        countyId: ''
      },
      refreshTableKey: '0',
      // 组件数据
      isEnableSpan: 20,
      setid: '1',
      btn: '',
      btnshow: false,
      filterText: '',
      backFormField1: {},
      arr: []
    }
  },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val)
    },
    'formField.provinceId'(id) {
      // if (this.provinceId !== id) {
      //   this.formField.cityId = ''
      //   this.formField.countyId = ''
      //   this.city(id, this.tableComponents1)
      // }
      if (this.tableComponent === this.tableComponents) {
        this.city(id, this.tableComponents)
      } else {
        this.city(id, this.tableComponents1)
      }
    },
    'formField.cityId'(id) {
      // if ((this.getCityId !== id) && (this.getCityId !== undefined)) {
      //   this.county(id, this.tableComponents1)
      // }
      if (this.tableComponent === this.tableComponents) {
        this.county(id, this.tableComponents)
      } else {
        this.county(id, this.tableComponents1)
      }
    },
    'formField.countyId'(id) {
      this.getCode()
    }
  },
  mounted() {
    this.init()
  },
  methods: {
    // 重置
    newreset() {
      if (this.resetstatus === '1') {
        this.reset()
      } else {
        this.formField = this.backFormField1
        this.setid += 1
        console.log(this.backFormField1)
      }
    },
    getCode() {
      for (const k in this.provinceList) {
        if (this.provinceList[k].provinceId === this.formField.provinceId) {
          this.formField.provinceCode = this.provinceList[k].provinceCode
        }
      }
      for (const k in this.cityList) {
        if (this.cityList[k].cityId === this.formField.cityId) {
          this.formField.cityCode = this.cityList[k].cityCode
        }
      }
      for (const k in this.countyList) {
        if (this.countyList[k].countyId === this.formField.countyId) {
          this.formField.countyCode = this.countyList[k].countyCode
        }
      }
    },
    county(id, tableComponent) {
      const select = []
      this.apiConfig = api.selectCommunity
      // // 先读取参数中的传输对象
      const returnObj = {
      // api配置
        apiConfig: this.apiConfig,
        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables: { cityId: id, isEnable: '1' }
      }
      // 转换了中台请求格式数据
      var paramD = this.$getParams(returnObj, null, this.dynamicApiStyle)
      // 调用中台API方法（可复用）
      this.$requestAPI(paramD, this.dynamicApiStyle).then(response => {
        if (response.result === '0') {
          if (response.msg) {
            this.$message({
              message: response.msg,
              type: 'warn',
              uration: 2000
            })
          }
          return
        }
        // 返回json

        this.countyList = Object.assign([], response.rows)
        this.getCode()
        for (const k in response.rows) {
          select.push({
            countyId: response.rows[k].countyId,
            countyName: response.rows[k].countyName
          })
        }
        for (const k in tableComponent) {
          if (tableComponent[k].codeField === 'countyId') {
            tableComponent[k].options = select
            return false
          }
        }
        // this.setid += 1
      }).catch(err => {
        console.info(err)
      })
    },
    city(id, tableComponent) {
      const select = []
      this.apiConfig = api.selectCity
      // // 先读取参数中的传输对象
      const returnObj = {
      // api配置
        apiConfig: this.apiConfig,
        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables: { provinceId: id, isEnable: '1' }
      }
      // 转换了中台请求格式数据
      var paramD = this.$getParams(returnObj, null, this.dynamicApiStyle)
      // 调用中台API方法（可复用）
      this.$requestAPI(paramD, this.dynamicApiStyle).then(response => {
        if (response.result === '0') {
          if (response.msg) {
            this.$message({
              message: response.msg,
              type: 'warn',
              uration: 2000
            })
          }
          return
        }
        // 返回json
        this.cityList = Object.assign([], response.rows)
        this.getCode()
        for (const k in response.rows) {
          select.push({
            cityId: response.rows[k].cityId,
            cityName: response.rows[k].cityName
          })
        }
        for (const k in tableComponent) {
          if (tableComponent[k].codeField === 'cityId') {
            tableComponent[k].options = select

            return false
          }
        }
      }).catch(err => {
        console.info(err)
      })
    },
    province(tableComponent) {
      const select = []
      this.apiConfig = api.selectProvince
      // // 先读取参数中的传输对象
      const returnObj = {
      // api配置
        apiConfig: this.apiConfig,
        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables: { isEnable: '1' }
      }
      // 转换了中台请求格式数据
      var paramD = this.$getParams(returnObj, null, this.dynamicApiStyle)
      // 调用中台API方法（可复用）
      this.$requestAPI(paramD, this.dynamicApiStyle).then(response => {
        if (response.result === '0') {
          if (response.msg) {
            this.$message({
              message: response.msg,
              type: 'warn',
              uration: 2000
            })
          }
          return
        }
        // 返回json
        this.provinceList = Object.assign([], response.rows)
        this.getCode()
        for (const k in response.rows) {
          select.push({
            provinceId: response.rows[k].provinceId,
            provinceName: response.rows[k].provinceName
          })
        }
        for (const k in tableComponent) {
          if (tableComponent[k].codeField === 'provinceId') {
            tableComponent[k].options = select
            return false
          }
        }
      }).catch(err => {
        console.info(err)
      })
    },
    // 触发页面显示配置的筛选
    filterNode(value, data, node) {
      // 如果什么都没填就直接返回
      if (!value) return true
      // 如果传入的value和data中的label相同说明是匹配到了
      if (data.label.indexOf(value) !== -1) {
        return true
      }
      // 否则要去判断它是不是选中节点的子节点
      return this.checkBelongToChooseNode(value, data, node)
    },
    // 判断传入的节点是不是选中节点的子节点
    checkBelongToChooseNode(value, data, node) {
      const level = node.level
      // 如果传入的节点本身就是一级节点就不用校验了
      if (level === 1) {
        return false
      }
      // 先取当前节点的父节点
      let parentData = node.parent
      // 遍历当前节点的父节点
      let index = 0
      while (index < level - 1) {
        // 如果匹配到直接返回
        if (parentData.data.label.indexOf(value) !== -1) {
          return true
        }
        // 否则的话再往上一层做匹配
        parentData = parentData.parent
        index++
      }
      // 没匹配到返回false
      return false
    },

    // 切换
    handleNodeClick(menueList, Node) {
      this.resetstatus = '1'
      this.menueListBF = menueList
      this.nodeBF = Node
      this.color = true
      // this.formField = {
      //   provinceId: '',
      //   cityId: '',
      //   countyId: ''
      // }
      if (Node.level === 1) {
        this.resetstatus = '0'
        const objs = {
          dlrId: menueList.dlrId,
          dlrCode: menueList.dlrCode,
          provinceId: '',
          cityId: '',
          countyId: '',
          carHouseCode: '',
          carHouseName: '',
          carHouseManager: '',
          carHouseTel: '',
          carHouseFax: '',
          zip: '',
          carHouseAddr: '',
          isDefaultAddr: '',
          isEnable: '',
          remark: '',
          provinceCode: '',
          cityCode: '',
          countyCode: ''
        }
        setTimeout(() => {
          this.formField = Object.assign(this.formFieldBF, objs)
          console.log(this.formField)
          this.type = 1
          this.btnshow = false
          this.tableComponent = this.tableComponents
          this.formtitle = '仓库信息维护'
          this.setid += 1
        }, 0)
        this.province(this.tableComponents)
      } else if (Node.level === 2) {
        this.type = 2
        this.editData(api.selectCarStockHouse, { carStockHouseId: menueList.carStockHouseId })
        this.btnshow = true
        this.tableComponent = this.tableComponents1
        this.btn = '新增储区'
        this.formtitle = '仓库信息维护'
        this.province(this.tableComponents1)
      } else if (Node.level === 3) {
        this.type = 3
        this.editData(api.selectCarStockArea, { carStockAreaId: menueList.carStockAreaId })
        this.btnshow = true
        this.tableComponent = this.tableComponents2
        this.btn = '新增库位'
        this.formtitle = '储区信息维护'
      } else if (Node.level === 4) {
        this.type = 4
        this.btnshow = false
        this.tableComponent = this.tableComponents3
        this.formtitle = '库位信息维护'
        this.editData(api.selectCarStockPlace, { carStockPlaceId: menueList.carStockPlaceId })
      }
      this.dynamicButton = this.dynamicButtons
      this.setid += 1
      // this.car()
    },
    // 新增仓库 新增储区
    add(btn) {
      this.resetstatus = '0'
      this.formField = {}
      if (btn === '新增库位') {
        this.formField = {
          carHouseName: this.name,
          carStockHouseId: this.houseId,
          carHouseCode: this.carHouseCode,
          carAreaCode: this.carAreaCode,
          carStockAreaId: this.carStockAreaId,
          carPlaceCode: '',
          isEnable: '',
          remark: ''
        }
        this.backFormField1 = JSON.parse(JSON.stringify(this.formField))
        this.btnshow = false
        this.formtitle = '新增库位'
        this.tableComponent = this.tableComponents4
        this.setid += 1
      } else {
        // 新增储区
        this.formField = {
          carAreaName: this.carAreaName,
          carHouseName: this.name,
          carStockHouseId: this.houseId,
          carHouseCode: this.carHouseCode,
          carAreaCode: '',
          carAreaManager: '',
          isEnable: '',
          remark: ''
        }
        this.backFormField1 = JSON.parse(JSON.stringify(this.formField))
        this.btnshow = false
        this.formtitle = '新增储区'
        this.tableComponent = this.tableComponents5
        this.setid += 1
      }
      console.log(this.formField)
    },

    save() {
      this.$utils.validataMoth(this, 'validpage')
      if (this.valid) {
      // 新增仓库
        if (this.type === 1 && this.formtitle === '仓库信息维护') {
          this.apiConfig = api.addStockHouse
          this.car()
        }
        // 仓库编辑
        if (this.type === 2 && this.formtitle === '仓库信息维护') {
          this.apiConfig = api.updateStockHouse
          this.car()
        }
        // 新增储区
        if (this.type === 2 && this.formtitle === '新增储区') {
          this.apiConfig = api.addStockArea
          this.car()
        }
        // 新增库位
        if (this.type === 3 && this.formtitle === '新增库位') {
          this.apiConfig = api.addStockPlace
          this.car()
        }
        // 编辑储区
        if (this.type === 3 && this.formtitle === '储区信息维护') {
          this.apiConfig = api.updateStockArea
          this.car()
        }
        if (this.type === 4 && this.formtitle === '库位信息维护') {
          this.apiConfig = api.updateStockPlace
          this.car()
        }
      }
    },
    car() {
      const that = this
      that.formloading = true
      // // 先读取参数中的传输对象
      const returnObj = {
      // api配置
        apiConfig: this.apiConfig,
        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables: this.formField
      }
      // 转换了中台请求格式数据
      var paramD = this.$getParams(returnObj, null, this.dynamicApiStyle)
      // 调用中台API方法（可复用）
      this.$requestAPI(paramD, this.dynamicApiStyle).then(response => {
        that.formloading = false
        if (response.result === '0') {
          if (response.msg) { this.$message({ message: response.msg, type: 'warn', uration: 2000 }) }
          return
        }
        // 返回json
        this.list = response.rows
        this.handleNodeClick(this.menueListBF, this.nodeBF)
        this.init()
        // this.color = false
        // this.tableComponent = {}
        // this.btnshow = false
        // this.setid += 1
        that.$message({ message: response.msg })
      }).catch(err => {
        console.info(err)
      })
    },

    // 查询
    editData(url, id) {
      this.apiConfig = url
      const that = this
      // // 先读取参数中的传输对象
      const returnObj = {
      // api配置
        apiConfig: that.apiConfig,
        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables: id
      }
      // 转换了中台请求格式数据
      var paramD = that.$getParams(returnObj, null, that.dynamicApiStyle)
      // 调用中台API方法（可复用）
      this.$requestAPI(paramD, that.dynamicApiStyle).then(response => {
        if (response.result === '0') {
          if (response.msg) {
            this.$message({
              message: response.msg,
              type: 'warn',
              uration: 2000
            })
          }
          return
        }
        // 返回json
        if (that.type === 2 && that.formtitle === '仓库信息维护') {
          var obj1 = JSON.parse(JSON.stringify(that.formField))
          Object.assign(obj1, response.rows[0])
          that.formField = obj1
          // this.getCityId = response.rows[0].cityId // 得到城市id，清空区县
          this.name = response.rows[0].carHouseName
          this.houseId = response.rows[0].carStockHouseId
          this.carHouseCode = response.rows[0].carHouseCode
          // this.provinceId = response.rows[0].provinceId // 省id
          that.setid += 1
        }
        if (that.type === 3) {
          var obj = JSON.parse(JSON.stringify(that.formField))
          Object.assign(obj, response.rows[0])
          that.formField = obj
          this.name = response.rows[0].carHouseName
          this.houseId = response.rows[0].carStockHouseId
          this.carHouseCode = response.rows[0].carHouseCode
          this.carAreaCode = response.rows[0].carAreaCode
          this.carStockAreaId = response.rows[0].carStockAreaId
          that.setid += 1
        }
        if (that.type === 4) {
          var obj2 = JSON.parse(JSON.stringify(that.formField))
          Object.assign(obj2, response.rows[0])
          that.formField = obj2
          that.setid += 1
        }
      })
    },

    init() {
      const that = this
      this.apiConfig = api.selectDlrList
      // // 先读取参数中的传输对象
      const returnObj = {
      // api配置
        apiConfig: this.apiConfig,
        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables: this.formField
      }
      // 转换了中台请求格式数据
      var paramD = this.$getParams(returnObj, null, this.dynamicApiStyle)
      // 调用中台API方法（可复用）
      this.$requestAPI(paramD, this.dynamicApiStyle).then(response => {
        if (response.result === '0') {
          if (response.msg) {
            this.$message({
              message: response.msg,
              type: 'warn',
              uration: 2000
            })
          }
          return
        }
        // 返回json
        setTimeout(() => {
          that.tree(response.rows)
        }, 0)
      }).catch(err => {
        console.info(err)
      })
    },

    // 修改tree
    tree(treeData) {
      this.menueList = JSON.parse(JSON.stringify(treeData).replace(/"dlrFullName"/g, '"label"').replace(/"StockHouse"/g, '"children"').replace(/"carHouseName"/g, '"label"').replace(/"carStockArea"/g, '"children"').replace(/"carAreaCode"/g, '"label"').replace(/"StockPlace"/g, '"children"').replace(/"carPlaceCode"/g, '"label"'))
    }
  }
}
</script>
<style lang="scss" scoped>
div.el-input{
    width: 90% !important;
    outline: none;
    margin:10px 5% !important;
}
#TreeTable{
  height:  100% !important;
}
/deep/ .mixButton{
  padding-top:20px;
  margin-bottom:-10px;
  margin-left:3%;
}

</style>
